<template>
<div>
<table>
  <tr v-for="i in list" :key="i">
    <td><van-button @click="get_id(i.id)">{{i.name}}</van-button></td>
  </tr>
</table>
  <div v-show="show_xiaoshuo">
    测试
    {{dict}}
    <table>
      <tr v-for="i in dict" :key="i">
        <td>{{i.name}}</td>
        <van-button @click="update_state(i.id,2)">通过</van-button>
        <van-button @click="update_state(i.id,3)">不通过</van-button>
      </tr>
    </table>
  </div>
  <div v-show="show_gift">
    测试
    {{dict}}
    <table>
      <tr v-for="i in dicts" :key="i">
        <td>{{i.name}}</td>
        <td>{{i.ntegral}}</td>
        <td><van-button @click="update_innelese(i.id)">兑换</van-button></td>
      </tr>
    </table>
  </div>
</div>
</template>

<script>
export default {
name: "nobe_list",
  data(){
  return{
    list:[],
    show_xiaoshuo:false,
    dict:[],
    show_gift:false,
    dicts:[]
  }
  },
  mounted() {
  this.get_role()
  },
  methods:{
  // 兑换积分
    update_innelese(id){
      console.log(id)
      this.myaxios('http://localhost:8000/update_gift/','post',{'pid':id,'userid':localStorage.getItem('userid')})
          .then(res=>{
            console.log(res)
            alert(res.data.msg)

          })
    },
    update_state(id,pid){
      this.myaxios('http://localhost:8000/update_inneroal','get',{'id':id,'pid':pid})
          .then(res=>{
            console.log(res)

          })
    },
    get_id(id){
      console.log(id)
      if (id==3){
        this.show_xiaoshuo=true
        this.get_xiaoshuo()
      }
      if (id==2){
        this.show_gift=true
        this.get_lipin()
      }
    },
  get_role(){
    this.myaxios('http://localhost:8000/get_nobe','get',{'userid':localStorage.getItem('userid')})
    .then(res=>{
      console.log(res)
      this.list=res.data.data
    })
  },
    get_xiaoshuo(){
      this.myaxios('http://localhost:8000/get_inneroal','get',{})
          .then(res=>{
            console.log(res)
            this.dict=res.data.res
          })
    },
    // 获取礼品
    get_lipin(){
      this.myaxios('http://localhost:8000/get_gift','get',{})
          .then(res=>{
            console.log(res)
            this.dicts=res.data.data
          })
    },
  }
}
</script>

<style scoped>

</style>
